package xddq

import (
	"fmt"
	D "websocket_apn/define"
	"websocket_apn/log"
	"websocket_apn/proto"
)

/*
  - ID:95CFD304 Name: MainIndex:9601 SubIndex:01

Activity_GOOD_FORTUNE - ID:93E9C804 Name: MainIndex:6B SubIndex:01
  - ID:97C6D304 Name: MainIndex:9501 SubIndex:01

Activity_TREASURE_BOWL - ID:91E9C804 Name: MainIndex:63 SubIndex:01
  - ID:97FFD204 Name: MainIndex:2E SubIndex:01
  - ID:91FDD204 Name: MainIndex:27 SubIndex:01
  - ID:92C8D304 Name: MainIndex:78 SubIndex:02
  - ID:95E9C804 Name: MainIndex:0D SubIndex:01
  - ID:9FE9C804 Name: MainIndex:18 SubIndex:01
  - ID:81E9C804 Name: MainIndex:67 SubIndex:01
  - ID:8CFDD204 Name: MainIndex:6E SubIndex:02
  - ID:8BE9C804 Name: MainIndex:5D SubIndex:01
  - ID:8DE9C804 Name: MainIndex:1E SubIndex:01

Activity_Xian_Yuan - ID:B1E9C804 Name: MainIndex:15 SubIndex:01
Activity_Fortune - ID:A6A10F Name: MainIndex:19 SubIndex:01
Activity__FESTIVAL_CELEBRATIONS - ID:BC8FD204 Name: MainIndex:31 SubIndex:0E
  - ID:BBE9C804 Name: MainIndex:12 SubIndex:05
  - ID:BFE9C804 Name: MainIndex:12 SubIndex:0A
  - ID:A3E9C804 Name: MainIndex:08 SubIndex:01
  - ID:A7E9C804 Name: MainIndex:64 SubIndex:01
  - ID:A3A3D304 Name: MainIndex:4E SubIndex:04
  - ID:AEC3D304 Name: MainIndex:9201 SubIndex:01
  - ID:AFE9C804 Name: MainIndex:58 SubIndex:01
  - ID:D7E9C804 Name: MainIndex:12 SubIndex:15
  - ID:D5E9C804 Name: MainIndex:7B SubIndex:01
  - ID:C7E9C804 Name: MainIndex:57 SubIndex:01
  - ID:C5E9C804 Name: MainIndex:7C SubIndex:01
  - ID:CBE9C804 Name: MainIndex:04 SubIndex:01

Activity_SELF_SELECT_GIFT - ID:C9E9C804 Name: MainIndex:1A SubIndex:01
Activity_Reincarnation_Jin_Guai - ID:DABB1B Name: MainIndex:2D SubIndex:01
Activity_SUPER_VALUE_GIFT - ID:CDE9C804 Name: MainIndex:02 SubIndex:01
  - ID:F6E8C804 Name: MainIndex:31 SubIndex:04
*/
func (xd *XdDriver) CheckActivityInfoData(allInfo []D.ActivityInfo) {
	for _, info := range allInfo {
		activityIndex := -1
		if len(info.MainIndex) == 0 || info.SubIndex == 0 {
			continue
		} else if info.MainIndex[0] == 0x02 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_SUPER_VALUE_GIFT
		} else if info.MainIndex[0] == 0x0E && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Ruins_Battle
		} else if info.MainIndex[0] == 0x15 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Xian_Yuan
		} else if info.MainIndex[0] == 0x19 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Fortune
		} else if info.MainIndex[0] == 0x1A && info.SubIndex == 0x01 {
			activityIndex = D.Activity_SELF_SELECT_GIFT
		} else if info.MainIndex[0] == 0x2E && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Accumulated_Recharge
		} else if info.MainIndex[0] == 0x2F && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Day_Recharge
		} else if info.MainIndex[0] == 0x2D && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Reincarnation_Jin_Guai
			task := xd.GetTaskByID(proto.S_SPIRIT_DRAW)
			task.MaxRunCount = 8
		} else if info.MainIndex[0] == 0x2D && info.SubIndex == 0x02 {
			activityIndex = D.Activity_Reincarnation_Shen_Tong
		} else if info.MainIndex[0] == 0x2D && info.SubIndex == 0x04 {
			activityIndex = D.Activity_Reincarnation_Ling_Shou
		} else if info.MainIndex[0] == 0x2D && info.SubIndex == 0x07 {
			activityIndex = D.Activity_Reincarnation_Nei_Dan
		} else if info.MainIndex[0] == 0x2D && info.SubIndex == 0x08 {
			activityIndex = D.Activity_Reincarnation_Xuan_Jue
		} else if info.MainIndex[0] == 0x2D && info.SubIndex == 0x09 {
			activityIndex = D.Activity_Reincarnation_Jian_Zhu
		} else if info.MainIndex[0] == 0x2D && info.SubIndex == 0x0A {
			activityIndex = D.Activity_Reincarnation_Fa_Bao
		} else if info.MainIndex[0] == 0x2D && info.SubIndex == 0x0B {
			activityIndex = D.Activity_Reincarnation_Fa_Xiang
		} else if info.MainIndex[0] == 0x31 && info.SubIndex == 0x0E {
			activityIndex = D.Activity_FESTIVAL_CELEBRATIONS
		} else if info.MainIndex[0] == 0x32 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_WILD_ZONE
		} else if info.MainIndex[0] == 0x35 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_UNION_BATTLE
		} else if info.MainIndex[0] == 0x3B && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Conquer_Eight_Wildernesses
		} else if info.MainIndex[0] == 0x3C && info.SubIndex == 0x01 {
			activityIndex = D.Activity_UNION_AREA_WAR
		} else if info.MainIndex[0] == 0x3D && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Ask_Grand_Event
		} else if info.MainIndex[0] == 0x40 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Monster_City_Treasure_Hunt
		} else if info.MainIndex[0] == 0x40 && info.SubIndex == 0x05 {
			activityIndex = D.Activity_Dragon_Palace_TREASURE
		} else if info.MainIndex[0] == 0x44 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_GOD_ISLAND_GAME_PLANT
		} else if info.MainIndex[0] == 0x47 && info.SubIndex == 0x03 {
			activityIndex = D.Activity_FAIRY_RABBIT
		} else if info.MainIndex[0] == 0x63 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_TREASURE_BOWL
		} else if info.MainIndex[0] == 0x6B && info.SubIndex == 0x01 {
			activityIndex = D.Activity_GOOD_FORTUNE
		} else if info.MainIndex[0] == 0x6C && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Dragon_Cave_Secret_Realm
		} else if info.MainIndex[0] == 0x74 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Demon_Spirit_Pagoda
		} else if info.MainIndex[0] == 0x77 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Refining_Conference
		} else if info.MainIndex[0] == 0x78 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Xiantu_Gathering
		} else if info.MainIndex[0] == 0x78 && info.SubIndex == 0x02 {
			activityIndex = D.Activity_Journey_Nine_Heavens_Together
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0x82 && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Summoning_Dragon
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0x83 && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Four_Sacred_Treasure_Realms
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0x85 && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Xuanmen_Tribute
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0x86 && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Refining_Treasure
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0x86 && info.MainIndex[1] == 0x01 && info.SubIndex == 0x02 {
			activityIndex = D.Activity_Reshaping_Dharma_Body
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0x8A && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Sect_Comparison
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0x92 && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Fairyland_Painting
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0x96 && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Immortal_Domain_Business_Journey
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0x99 && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Xianyuan_Treasure_Pavilion
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0x9A && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Baohuatang
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0xA1 && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_VALENTINES_DAY
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0xAA && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Attracting_Wealth_And_Prosperity
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0xAB && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Flying_Sword_Treasure
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0xAC && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Reincarnation_Secret_Realm
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0xAD && info.MainIndex[1] == 0x01 && info.SubIndex == 0x02 {
			activityIndex = D.Activity_Guard_Fairy_Tree
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0xAE && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Xuanchen_Remembers_Dreams
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0xBA && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_We_Yound_Scene
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0xC7 && info.MainIndex[1] == 0x01 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Kun_Lun_War
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0xAD && info.MainIndex[1] == 0x02 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Road_Defend
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0xB0 && info.MainIndex[1] == 0x02 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Pupil
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0xB1 && info.MainIndex[1] == 0x02 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Heaven_Battle
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0xB7 && info.MainIndex[1] == 0x02 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_XIYOU_PLAYER_BRESS
		} else if len(info.MainIndex) == 2 && info.MainIndex[0] == 0xC1 && info.MainIndex[1] == 0x02 && info.SubIndex == 0x01 {
			activityIndex = D.Activity_Yu_Kui

		}
		if activityIndex >= 0 {
			xd.UserData.Activity[activityIndex] = info
		}
		log.Infof("%s - ID:%s Name:%s MainIndex:%X SubIndex:%02X", D.ActivityList[activityIndex], info.ID, info.Name, info.MainIndex, info.SubIndex)
	}
}

func (xd *XdDriver) CheckConditionListInfoData(allInfo []D.ConditionListInfo) {
	for _, info := range allInfo {
		for _, task := range info.Task {
			if info.ActivityID == xd.UserData.Activity[D.Activity_XIYOU_PLAYER_BRESS].ID {
				if task.FinishFlag {
					log.Debugf("西游伏魔-任务[%s]已完成 进度%d 完成时间 %s", task.TaskID, task.Progress, task.FinishTime.Format("2006-01-02 15:04:05"))
				} else {
					log.Debugf("西游伏魔-任务[%s]未完成 进度%d ", task.TaskID, task.Progress)
				}
			}
			if task.FinishFlag && !task.GetFlag {
				log.Infof("活动[%s] 任务[%s]已完成 进度%d 完成时间%s", info.ActivityID, task.TaskID, task.Progress, task.FinishTime.Format("2006-01-02 15:04:05"))
				xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_ACTIVITY_GET_CONDITION_REWARD_BY_ARR, fmt.Sprintf("0A %02d 08 %s 10 %s", len(info.ActivityID+task.TaskID)/2+2, info.ActivityID, task.TaskID)))
				xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_ACTIVITY_GET_CONDITION_REWARD, fmt.Sprintf("08 %s 10 %s", info.ActivityID, task.TaskID)))
			}
		}
	}
}
